package com.huangsm.cloud.consumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * Ribbon方式负载均衡
 * RestTemplate+Ribbon实现服务的调用
 * 不能让RibbonConfig和启动类在同一个包下，防止所有服务的负载均衡算法一致
 * 否则需要
 * @author huangsm
 * @version V1.0
 */
@SpringBootApplication
@EnableEurekaClient
//@RibbonClient(name = "service-provider",configuration = RibbonConfig.class)
//@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,value = ExcludeFromComponetScan.class)})
public class ConsumerRibbonApplication {

	/**
	 * @LoadBalanced 负载均衡
	 * @return
	 */
	@LoadBalanced
	@Bean(name = "restTemplate1")
	public RestTemplate restTemplate(){
		return new RestTemplate();
	}
	public static void main(String[] args) {
		SpringApplication.run(ConsumerRibbonApplication.class, args);
	}

}

